<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
    <div>
      <h2>第九章 闭包与作用域</h2>
      <button>收藏课程</button>
    </div>
  
  <script>
  new Promise(resolve => {
    document.querySelector("button").addEventListener("click", e => {
      resolve();
    });
  })
  .then(() => {
    return new Promise(resolve => {
      setTimeout(() => {
        console.log("执行收藏任务");
        resolve();
      }, 2000);
    });
  })
  .then(() => {
    return new Promise(resolve => {
      setTimeout(() => {
        console.log("更新积分");
        resolve();
      }, 2000);
    });
  })
  .then(() => {
    console.log("收藏成功！奖励10积分");
  })
  .catch(error => console.log(errro));
  </script>
</body>
</html>